\section{Cost function}
Given a number of scalar functions $f_n(\vec{x})$ where $n=1,2\ldots N$ and
\begin{align}
\vec{x} &= \sum_i x_i \hat{x}_i\label{eqn:indvarx}
\end{align}
the question arises is to how these functions can be combined together to form one single scalar function, which will be known as the \emph{cost function}.  What different operators can be used and how do they affect the overall cost function?

One possibility is to look at $f_n(\vec{x})$ as the components of a vector that span an $n^{th}$ dimensional space which can be written as,
\begin{align}
	\vec{f}(\vec{x}) &= \sum_n f_n(\vec{x}) \hat{f}_n\label{eqn:veccostfcn}
\end{align}
One very natural way of forming the cost function is to then define it as the \emph{length} or \emph{norm} of the vector.  In general this can be defined as follows,
\begin{align}
	||\vec{f}(\vec{x})|| &= \left(\sum_n |f_n(\vec{x})|^p\right)^{\frac{1}{p}}\label{eqn:pnorm}
\end{align}
which is known as the \emph{p-norm}.  If $p$ is even, then the function will always be positive and the absolute value operator is no longer needed. If $p=2$ then (\ref{eqn:pnorm}) reduces to,
\begin{align}
	||\vec{f}(\vec{x})|| &= \sqrt{\sum_n f_n^2(\vec{x})}\label{eqn:euclideannorm}
\end{align}
which is seen to be the \emph{Euclidean norm}.  One interesting possibility is in the limit when $p\rightarrow\infty$.  
\begin{align}
	||\vec{f}(\vec{x})|| &= \lim_{p\rightarrow\infty}\left(\sum_n |f_n(\vec{x})|^p\right)^{\frac{1}{p}}=\max(|f_n(\vec{x})|)\label{eqn:infinitynorm}
\end{align}
which is called the \emph{infinity norm}.

\section{Gradient of a scalar function}

The gradient of a scalar function is defined as,
\begin{align}
	\nabla f(\vec{x}) &= \sum_i \frac{\partial f(\vec{x})}{\partial x_i} \hat{x_i}\label{eqn:gradfunc}
\end{align}
which can be seen to be a vector the same length as $\vec{x}$ and whose elements are the partial derivatives with respect to $x_i$.  The gradient of (\ref{eqn:pnorm}) is calculated to be,
\begin{align}
	\nabla f(\vec{x}) &= \sum \frac{\partial ||\vec{f}(\vec{x})||}{\partial x_i} \hat{x_i}
\end{align}
where,
\begin{align}
	\frac{\partial ||\vec{f}(\vec{x})||}{\partial x_i} &= \frac{\partial}{\partial x_i} \left(\sum_n |f_n(\vec{x})|^p\right)^{\frac{1}{p}}\\
	&= \frac{1}{p} \left(\sum_n |f_n(\vec{x})|^p\right)^{{\frac{1}{p}}-1}\sum_n p|f_n(\vec{x})|^{p-1}\frac{\partial |f_n(\vec{x})|}{\partial x_i}\\
	&= \frac{||\vec{f}(\vec{x})||}{\sum_n |f_n(\vec{x})|^p}\sum_n\frac{|f_n(\vec{x})|^{p}}{|f_n(\vec{x})|}\frac{\partial |f_n(\vec{x})|}{\partial x_i}\label{eqn:partialpnorm}
\end{align}

If $p=2$ the partial derivatives of the Euclidean norm is found to be,
\begin{align}
	\frac{\partial ||\vec{f}(\vec{x})||}{\partial x_i} &= \frac{1}{||\vec{f}(\vec{x})||}\sum_n f_n(\vec{x})\frac{\partial f_n(\vec{x})}{\partial x_i}
\end{align}
where $||\vec{f}(\vec{x})||$ is defined in (\ref{eqn:euclideannorm}).  

The partial derivatives of the infinity norm is found by taking the limit of (\ref{eqn:partialpnorm}) as $p\rightarrow\infty$ to get,
\begin{align}
	\frac{\partial ||\vec{f}(\vec{x})||}{\partial x_i} &= \lim_{p\rightarrow\infty}\left(\frac{||\vec{f}(\vec{x})||}{\sum_n |f_n(\vec{x})|^p}\sum_n\frac{|f_n(\vec{x})|^{p}}{|f_n(\vec{x})|}\frac{\partial |f_n(\vec{x})|}{\partial x_i}\right)\\
	 &=\frac{\partial |f_{n_{max}}(\vec{x})|}{\partial x_i}\label{eqn:partialinfinitynorm}
\end{align}
where $n_{max}$ is the index at where (\ref{eqn:infinitynorm}) is true.